//
//  WCNGenralVC.m
//  WCN
//
//  Created by wsj2015 on 15/11/1.
//  Copyright © 2015年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "WCNGenralVC.h"

#import "WCNSwitchItemView.h"
#import "WCNCaseVC.h"
#import "WCNNewsVC.h"
@interface WCNGenralVC ()
{
    NSInteger _selectItem;
    WCNCaseVC *_caseVC;
    WCNNewsVC *_newsVC;
    
    UIView *_contentView;
    
}
@end

@implementation WCNGenralVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor =[UIColor greenColor];
    self.navigationController.navigationBar.translucent = NO;
    WCNSwitchItemView *switchControl =[[WCNSwitchItemView alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
    switchControl.changeItemBlock = ^(NSInteger selectItemIndex){
        _selectItem =selectItemIndex;
        [self switchController];
    };
    self.navigationItem.titleView =switchControl;
    
    _caseVC  =[[WCNCaseVC alloc] init];
    _newsVC  =[[WCNNewsVC alloc]  init];
    //    _oneVC.navigationItem
    [self addChildViewController:_caseVC];
    [self addChildViewController:_newsVC];
    
    _contentView =[[UIView alloc]initWithFrame:CGRectMake (0, -20, self.view.frame.size.width,self.view.frame.size.height)];
    _contentView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:_contentView];
    
    [_contentView addSubview:_newsVC.view];
    
    
}
- (void)switchController
{
    if (_selectItem == 0) {
        
        [self transitionFromOldViewController:_caseVC toNewViewController:_newsVC];
        
        
        
        
    }else{
        [self transitionFromOldViewController:_newsVC toNewViewController:_caseVC];
        
        
    }
}
//转换子视图控制器
- (void)transitionFromOldViewController:(UIViewController *)oldViewController toNewViewController:(UIViewController *)newViewController{
    
    [self transitionFromViewController:oldViewController toViewController:newViewController duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:^(BOOL finished) {
        
    }];
}



@end
